import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const state = {
    count : 44
}

const mutations = {
  jia(state,obj){
    state.count+=obj.a
  },
  jian(state){
    state.count--
  }
}

const getters = {
  count:function(state){
      //alert(2);
    return state.count += 100
  }
}

const actions = {
  jiaplus (context){
    context.commit('jia',{a:1})
    setTimeout(()=>{
        context.commit("jian")
    },3000)
    console.log("我被执行了");
  },
  
  jianplus ({commit}){
    commit("jian")
  }
}

export default new Vuex.Store({
    state,
    mutations,
    getters,
    actions
})